<%@ page language="java" contentType="text/html; charset=utf-8" %>
<jsp:useBean id="rs" class="weaver.conn.RecordSet" scope="page"/>
<jsp:useBean id="bb" class="weaver.general.BaseBean"/>
<%@ page import="com.alibaba.fastjson.JSONObject" %>
<%@ page import="weaver.general.Util" %>
<%@ page import="java.math.BigDecimal" %>
<%@ page import="com.alibaba.fastjson.JSONArray" %>
<%@ page import="weaver.hrm.User" %>
<%@ page import="weaver.hrm.HrmUserVarify" %>
<%@ page import="weaver.conn.RecordSet" %>
<%
    JSONObject jsonData = new JSONObject();
    String requestid = Util.null2String( request.getParameter( "requestid" ) );
    User user = HrmUserVarify.getUser( request,response );
    String username = user.getLastname();
    String hymcs  ="";
    rs.executeQuery("select hymc from uf_ejmxtz where requestid=? group by hymc order by hymc",requestid);
    while (rs.next()){
        String hymc = Util.null2String( rs.getString( "hymc" ));
        hymcs += "".equals( hymcs ) ? hymc : "," + hymc;
    }

    JSONArray datasList = new JSONArray(  );
    String [] arr = hymcs.split( "," );
    for (String hymc:arr) {
        JSONObject datasJson = new JSONObject(  );
        datasJson.put("meetName",getMeetName(hymc));
        JSONArray dataList = new JSONArray(  );
        String yfjes = "0.00";
        String dkgss = "0.00";
        String sfjes = "0.00";
        rs.executeQuery("select xh,xm,sfzh,yfje,dkgs,sfje from uf_ejmxtz where hymc=? order by xh",hymc);
        if (rs.next()) {
            String xh = Util.null2String( rs.getString( "xh" ));
            String xm = Util.null2String( rs.getString( "xm" ));
            String sfzh = Util.null2String( rs.getString( "sfzh" ));
            String yfje = Util.null2String( rs.getString( "yfje" ));
            String dkgs = Util.null2String( rs.getString( "dkgs" ));
            String sfje = Util.null2String( rs.getString( "sfje" ));
            JSONObject datajson = new JSONObject(  );
            datajson.put("xh",xh);
            datajson.put("xm",xm);
            datajson.put("sfzh",sfzh);
            datajson.put("yfje",yfje);
            datajson.put("dkgs",dkgs);
            datajson.put("sfje",sfje);
            dataList.add(datajson);
            yfjes = fAdd(yfjes,yfje);
            dkgss = fAdd(dkgss,dkgs);
            sfjes = fAdd(sfjes,sfje);
        }
        datasJson.put("data",dataList);
        datasJson.put("yfjes",yfjes);
        datasJson.put("dkgss",dkgss);
        datasJson.put("sfjes",sfjes);
        datasJson.put("approverName","姜宏岩");
        datasJson.put("makeName",username);
        datasList.add( datasJson );
    }

    jsonData.put("datas",datasList);
    out.print( jsonData.toJSONString() );
%>
<%!
    public static String getMeetName(String id){
        RecordSet rs = new RecordSet(  );
        rs.executeQuery("select hymc from uf_xjhy where id=?",id);
        rs.next();
        return Util.null2String( rs.getString( "hymc" ));
    }
    public static String isZero(String a) {
        if ("".equals(a)) {
            a = "0";
        }
        return a;
    }
    // f点型相加
    public static String fAdd(String a, String b) {
        a = isZero(a);
        b = isZero(b);
        BigDecimal bg1 = new BigDecimal(a);
        BigDecimal bg2 = new BigDecimal(b);

        BigDecimal bd = bg1.add(bg2);

        return bd.toString();
    }
%>